<template>
  <div>
    <el-table :data="tableData.records" style="width: 100%">
      <el-table-column prop="rid" label="交易记录" width="180" />
      <el-table-column prop="mainCard" label="转账发起人" width="180" />
      <el-table-column prop="toCard" label="转账接收人" width="180" />
      <el-table-column prop="balance" label="交易记录" width="180" />
      <el-table-column prop="operatorStatus" label="交易类型" width="180">
        <template #default="scope">
          {{scope.row.operatorStatus == 0 ? '在线转账' : scope.row.operatorStatus == 1 ? '在线充值' : '在线提现'}}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="交易时间" width="600" />
      <el-table-column fixed="right" label="Operations" width="180">
        <template #default="scope">
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="handleDelete(scope.row.rid)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="tableData.current"
      v-model:page-size="tableData.size"
      :page-sizes="[5, 10, 15, 20]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Deletes, GetByListj } from '@/api/transfer'
import { ElMessage } from 'element-plus'

const tableData = ref([])

function handleDelete(rid) {
  console.log(rid)
  Deletes(rid).then(res => {
    if (res.code === 200) {
      ElMessage.success('删除成功')
      window.location.reload()
    } else {
      ElMessage.error('删除失败')
    }
  })
}

function handleSizeChange(val) {
  console.log(`${val} items per page`)
  findAll(tableData.value.current, val)
}
function handleCurrentChange(val) {
  console.log(`current page: ${val}`)
  findAll(val, tableData.value.size)
}

function findAll(offset, pagesize) {
  GetByListj(offset, pagesize).then(res => {
    console.log(res.data)
    tableData.value = res.data
  })
}
findAll()
</script>

<style scoped lang="scss"></style>
